package com.decent.wx.controller;

import com.decent.entity.common.Message;
import com.decent.wx.service.MeService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author 王雪杰
 * @date 2021/8/28 16:57
 */
@RestController
@RequestMapping("small-contract/api/v1")
public class MeController {
    @Resource
    private MeService meService;

    /**
     * 用来测试
     * https://www.small-contract.cn/small-contract/api/v1/hook/count?userKey=
     *
     * @param userKey anything
     * @return userKey
     */
    @RequestMapping("hook/count")
    public String count(String userKey) {
        System.out.println("hook/count?" + userKey);
        return userKey;
    }

    /**
     * 用来测试
     * https://www.small-contract.cn/small-contract/api/v1/hook/count?userKey=
     *
     * @param userKey anything
     * @return userKey
     */
    @RequestMapping("formId/fresh")
    public String fresh(String userKey) {
        System.out.println("formId/fresh" + userKey);
        return userKey;
    }

    /**
     * 小程序发送消息
     *
     * @return 响应
     */
    @RequestMapping("send")
    public Message send() {
        return meService.send();
    }

    /**
     * 获得openId
     *
     * @param code 前端wx.login(Object object)获得
     * @return openId
     * @throws Exception Exception
     */
    @RequestMapping("getOpenId")
    public String getOpenId(String code) throws Exception {
        return meService.getOpenId(code);
    }
}
